#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 100005;
int n; vector<int> To[MAXN]; priority_queue<pair<int, bool>> Q[MAXN];
void merge(priority_queue<pair<int, bool>> &l, priority_queue<pair<int, bool>> &r){
  if(l.size() < r.size()) swap(l, r);
  while(!r.empty()) l.push(r.top()), r.pop();
}
void DFS(int id, int fa = 0){
  for(int nxt: To[id]) if(nxt != fa) DFS(nxt, id), merge(Q[id], Q[nxt]);
  int now = 1; bool f = 0;
  if(Q[id].size() > 1) now += Q[id].top().first, f |= Q[id].top().second, Q[id].pop(), now += Q[id].top().first, f |= Q[id].top().second, Q[id].pop();
  else if(!Q[id].empty()){int x = Q[id].top().first; Q[id].pop(), Q[id].emplace(x, 1);};
  Q[id].emplace(now, f);
}
int main(){
  freopen("bird.in", "r", stdin);
  freopen("bird.out", "w", stdout);
  cin.tie(nullptr)->sync_with_stdio(false);
  cin >> n;
  for(int i = 1; i <  n; i++){
    int x, y; cin >> x >> y, To[x].push_back(y), To[y].push_back(x);
  }
  DFS(1), cout << Q[1].top().first + Q[1].top().second << '\n';
  return 0;
}
